<?php

/**
 * Description of learning_path_model
 *
 * @author phamtruong
 */
class search_model extends CI_Model {

    //put your code here
    public function __construct() {
        parent::__construct();
    }

    public function article($text) {
        //$text = $this->input->get("text");
//        $sql="select a.id, a.title, v.content,substr(v.content, 1,200) short_content,v.modified_date,r.rating
//            from article a, article_version v, article_rating r
//            where a.id=v.article_id 
//                 AND a.title like '%$text%'
//                 AND v.version=(select max(version) from article_version where article_id=a.id)
//                 AND r.rating=(select max(rating) from article_rating where article_id=a.id)";
        $sql=("select a.id, a.title, v.content,substr(v.content, 1,200) short_content,v.modified_date, m.fullname
            from article a, article_version v,member m
            where a.id=v.article_id 
                 AND a.title like '%$text%'
                 AND v.version=(select max(version) from article_version where article_id=a.id)
                 AND v.contributor_id=m.id

 ");
        $query = $this->db->query($sql);
        return $query->result_array();
    }

    public function learning_path($text) {
        //$text = $this->input->get("text");
//        $sql="select p.title,p.id ,m.description,substr(m.description,1,200) short_description,
//                v.modified_date, avg(r.rating) rating
//            from learning_path p,path_meta m,path_version v,path_rating r
//            where p.title like '%$text%'
//                AND p.id=v.learning_path_id
//                AND v.version=(select max(version) from path_version where learning_path_id=p.id)
//                AND v.path_meta_id=m.id
//                AND p.id=r.learning_path_id";
        $sql=("select p.title,p.id ,m.description,substr(m.description,1,200) short_description,
                v.modified_date,b.fullname
            from learning_path p,path_meta m,path_version v, member b
            where p.title like '%$text%'
                AND p.id=v.learning_path_id
                AND v.version=(select max(version) from path_version where learning_path_id=p.id)
                AND v.path_meta_id=m.id
                AND v.contributor_id=b.id");
        $query = $this->db->query($sql);
//        
//            
//            
//            
        return $query->result_array();
    }

    public function member($text) {
        //$text = $this->input->get("text");
        $this->db->select("*");
        $this->db->where("email like '%$text%'");
        $this->db->order_by("id desc");
        $this->db->limit(10, 0);
        $query = $this->db->get("member");
        return $query->result_array();
    }

    public function video($text) {
        //$text = $this->input->get("text");
        $query = $this->db->query("select v.id , v.title, d.created_date , m.fullname, substr(v.description,1,200) short_description
            from video v, video_discussion d, member m
            where v.title like '%$text%'
            and d.video_id = v.id 
            and m.id= v.member_id");
        return $query->result_array();
    }

}

/* End of file search_model.php */
/* Location: ./application/models/search_model.php */